/*全局变量*/
var GLOABAL_SYSTEMROOT = "";
var GLOABAL_SYSTEMROOT_ABS = "";
var GLOBALVAR_httpRoot = "http://" + GLOBALVAR_siteAddr;
var GLOBALVAR_socketRoot = "ws://" + GLOBALVAR_siteAddr + "/" + GLOBALVAR_appName + "/chatWebsocket";
var GLOBALVAR_rootUrl = GLOBALVAR_httpRoot + "/" + GLOBALVAR_appName;
var GLOBALVAR_imgRoot = GLOBALVAR_rootUrl + "/images/mobile";
var GLOBALVAR_rpcUrl = GLOBALVAR_rootUrl + "/business";
var GLOBALVAR_resourceUrl = GLOBALVAR_rootUrl + "/resource";
var GLOBALVAR_uploadPath = GLOBALVAR_rootUrl + "/upload";
var GLOBALVAR_uploadVoicePath = GLOBALVAR_uploadPath + "/lanResource/voiceResource/manual";
var GLOBALVAR_uploadMacVoicePath = GLOBALVAR_uploadPath + "/lanResource/voiceResource/machine";
var GLOBALVAR_uploadCombVoicePath = GLOBALVAR_uploadPath + "/lanResource/voiceResource/combine";
var GLOBALVAR_uploadImgPath = GLOBALVAR_uploadPath + "/topic/image";
var GLOBALVAR_uploadVoiceTopicPath = GLOBALVAR_uploadVoicePath + "/topic";
var GLOBALVAR_uploadImgTopicPath = GLOBALVAR_uploadImgPath + "/topic";
var GLOBALVAR_userAdioUrlPath = GLOBALVAR_uploadPath + "/userAudio";
var GLOBALVAR_storeRoot = "tnbRes";
var GLOBALVAR_storeResourceRoot = "tnbResource";
var GLOBALVAR_storeAppResource = GLOBALVAR_storeRoot + "/" + GLOBALVAR_storeResourceRoot;
var GLOBALVAR_storeResourceRealRoot= "resource";
var GLOBALVAR_storeResource = GLOBALVAR_storeRoot + "/" + GLOBALVAR_storeResourceRealRoot;
var GLOBALVAR_tempResource = GLOBALVAR_storeRoot + "/tempResource";
var GLOBALVAR_storeAudioFilePath = GLOBALVAR_storeRoot + "/audioChat";
var GLOBALVAR_storeTempResFilePath = GLOBALVAR_storeRoot + "/tempResource";
var GLOBALVAR_storeAudioTypePersonal = "personal";
var GLOBALVAR_storeAudioTypeTopic = "topic";
var GLOBALVAR_storeResVoicePath = GLOBALVAR_storeResource + "/voice";
var GLOBALVAR_storeResImgPath = GLOBALVAR_storeResource + "/image";
var GLOBALVAR_topicVoicePath = GLOBALVAR_storeResVoicePath + "/topic";
var GLOBALVAR_topicImagePath = GLOBALVAR_storeResImgPath + "/topic";
var GLOBALVAR_storeChatAudioFilePath = GLOBALVAR_storeAudioFilePath + "/" + GLOBALVAR_storeAudioTypePersonal;
var GLOBALVAR_storeTopicAudioFilePath = GLOBALVAR_storeAudioFilePath + "/" + GLOBALVAR_storeAudioTypeTopic;
var GLOBALVAR_topicImgFilePath =  "upload/topic/image";
var GLOBALVAR_userInfo = GLOBALVAR_uploadPath + "/Myinfo";
var GLOBALVAR_storeTopicImagePath = GLOBALVAR_storeResource + "/" + GLOBALVAR_topicImgFilePath;
var GLOBALVAR_userInfoPath = GLOBALVAR_storeResource + "/Myinfo";
var GLOBALVAR_noticeTag = "pushNoticeTag";

var GLOBAL_language = "chinese";

/*公共方法*/
function GLOBALFUN_getMode(){
    if (typeof GLOBALVAL_mode != 'undefined' && GLOBALVAL_mode=="phoneGap"){
    	return "phoneGap";
    }
    return "native";
};
function GLOBALFUN_getLanguage(){
    var language = localStorage.getItem("language");
    console.log("language in localStorage:" + language);
    if(!language){
    	language = "chinese";
    }
    return language;
};
function GLOBALFUN_setLanguage(language){
    localStorage.setItem("language",language);
    //还需要通知到native端
    if(websocketClient&&websocketClient.pushService){
    	websocketClient.setLanguage(language);
    }
};
function GLOBALFUN_switchLanguage(language){
    var language = GLOBALFUN_getLanguage();
    if(language=="chinese"){
    	language = "english";
    }else{
    	language = "chinese";
    }
    GLOBALFUN_setLanguage(language);
    return language;
};
function GLOBALFUN_getResFilePath(){
	var rootPath = "";
    if (typeof GLOBALVAL_mode != 'undefined' && GLOBALVAL_mode=="phoneGap"){
    	rootPath = GLOABEL_SYSTEMROOT;
    }
    var path = GLOBALVAR_storeResVoicePath;
    return path;
};
function GLOBALFUN_getTempFilePath(){
	var rootPath = "";
    if (typeof GLOBALVAL_mode != 'undefined' && GLOBALVAL_mode=="phoneGap"){
    	rootPath = GLOABEL_SYSTEMROOT;
    }
    var path = rootPath + "/" + GLOBALVAR_storeTempResFilePath;
    return path;
};
function GLOBALFUN_getChatAudioFilePath(){
	var rootPath = "";
    if (typeof GLOBALVAL_mode != 'undefined' && GLOBALVAL_mode=="phoneGap"){
    	rootPath = GLOABEL_SYSTEMROOT;
    }else{

    }
    var path = GLOBALVAR_storeChatAudioFilePath;
    return path;
};
function GLOBALFUN_getTopicAudioFilePath(){
	var rootPath = "";
    if (typeof GLOBALVAL_mode != 'undefined' && GLOBALVAL_mode=="phoneGap"){
    	rootPath = GLOABEL_SYSTEMROOT;
    }else{

    }
    var path = GLOBALVAR_storeTopicAudioFilePath;
    return path;
};
function GLOBALFUN_getTopicImgFilePath(){
    var path = GLOBALVAR_storeTopicImgFilePath;
    return path;
};
/*基础数据*/
var GLOBAL_VAR_dictData = {
	typeData: null,
	topicTypeData: null,//话题大类型
	//获取话题类型，用于级联下拉框绑定
	receiveTopicType: function(oriData){
		mylog("receiveTopicType call");
		var _self = this;
	  	var rpcCall = $.extend({},RpcCall,{
	 		async: false,
	 		action: 'YubanMobileAction.action',
	 		method: 'getTopicTypeList',
	 		params: [],
	 		processRequestData: function(data){
	 			//mydebug("processRequestData in receiveTopicType isss:" , data);
	 			//先把整个data存储到属性中
	 			_self.typeData = data.topicTypeList;
	 			var typeList = data.topicTypeList;
	 			_self.topicTypeData = new Array();
	 			//构造数组
				$.each(typeList,function(n,value) {
					var typeParent = value;
					//暂时只使用指定的类型
					if(typeParent.user_id||typeParent.user_id>0){
						return;
					}
					var typeArray = [typeParent.value,typeParent.id,0];
					_self.topicTypeData.push(typeArray);
				});
	 		}
		 });
		 //如果已经获取过了，则不需要再次获取
		 if(!this.typeData){
		 	mylog("no data");
			rpcCall.request();
		 }
		 if(oriData){
		 	return this.typeData;
		 }
		 return this.topicTypeData;
	},
	//根据id取得类型名称
	getValueByKey: function(typeId){
		mylog("getValueByKey in,typeId:" + typeId);
		var typeList = this.receiveTopicType(true);
		for(var i=0;i<typeList.length;i++){
			var topicType = typeList[i];
			mylog("topicType.id:" + topicType.id);
			if(topicType.id==typeId){
				return topicType.value;
			}
		};
		return "";
	},
	//字典数据中的中英文转换,commonType代表字典数据对象
	transferTypeValueLanguage: function(commonType){
		if(GLOBAL_language=="english"){
			commonType.value = commonType.valueEn;
		}
		mylog("commonType.value:" + commonType.value);
		return commonType;
	}
};
